home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14056 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help
  5. Date: 11 Apr 1996 16:14:29 GMT
  6. Organization: OpenVision
  7. Message-ID: <4kjb55$7fm@spanky.pls.ov.com>
  8. References: <316C3043.A5D@hlp.com>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article A5D@hlp.com, andrew kennedy <"andrew kennedy"@hlp.com> writes:
  13. >This is a multi-part message in MIME format.
  14. >
  15. >--------------66794A10240E
  16. >Content-Type: text/plain; charset=us-ascii
  17. >Content-Transfer-Encoding: 7bit
  18. >
  19. >I wrote this code early in my C career, but there should be a better to
  20. >do this. Can someone help.
  21. >
  22. >--------------66794A10240E
  23. >Content-Type: text/plain; charset=us-ascii
  24. >Content-Transfer-Encoding: 7bit
  25. >Content-Disposition: inline; filename="PROB"
  26. >
  27. >
  28. >       if( !strchr(file_name, '.')) /*if file has no extension, take on .enc*/
  29. >    {
  30. >      strcpy(name1,file_name);
  31. >      strcpy(name2,file_name);
  32. >      strcat(name2, ".enc");
  33. >    }
  34. >       else
  35. >    {
  36. >     strcpy(name1, file_name);
  37. >     strcpy(name2, file_name);
  38. >     strrev(name2);          /* reverse string i.e. hello = olleh */
  39. >     rev_string = strpbrk(name2,".");
  40. >                /* make rev_string contain only those */
  41. >                /* characters on right side of period */
  42. >                /* and then take off the period       */
  43. >                
  44. >                /* works ONLY with file names with    */
  45. >                /* the underscore, alphabetic and     */
  46. >                /* numeric characters                 */
  47. >
  48. >     rev_string = strpbrk(rev_string,"abcdefghijklmnopqrstuvwxyz_0123456789");
  49. >     strrev(rev_string);      /* reverse string again to get only */
  50. >     strcpy(name2,rev_string);/* filename without it's extension  */
  51. >     strcat(name2, ".enc");   /* copy .enc extension onto name2   */
  52. >    }
  53. >
  54. >--------------66794A10240E--
  55. >
  56.  
  57.  
  58. The untested code below will replace the extension with .enc.
  59.  
  60. strcpy(name1, file_name);  /* we need this copy in either case */
  61.  
  62. if (strchr(name1, '.'))
  63. {
  64.     *strchr(name1, '.') = '\0';  /* the if test above insures valid address */
  65. }
  66. sprintf(name2, "%s.enc", name1);
  67.  
  68.             Fletcher.Glenn@ov.com
  69.  
  70.